package com.sssre.lttcloud.dict.controller;

import com.sssre.lttcloud.api.entity.DictType;
import com.sssre.lttcloud.common.result.Result;
import com.sssre.lttcloud.dict.service.DictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 字典类型控制器
 */
@RestController
@RequestMapping("/dict/type")
@CrossOrigin
public class DictTypeController {

    @Autowired
    private DictTypeService dictTypeService;

    /**
     * 分页查询字典类型
     */
    @GetMapping("/page")
    public Result getDictTypePage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String dictName,
            @RequestParam(required = false) String dictType) {
        return dictTypeService.getDictTypePage(pageNum, pageSize, dictName, dictType);
    }

    /**
     * 查询所有字典类型
     */
    @GetMapping("/list")
    public Result getAllDictTypes() {
        return dictTypeService.getAllDictTypes();
    }

    /**
     * 根据ID查询字典类型
     */
    @GetMapping("/{id}")
    public Result getDictTypeById(@PathVariable Long id) {
        return dictTypeService.getDictTypeById(id);
    }

    /**
     * 新增字典类型
     */
    @PostMapping
    public Result addDictType(@Valid @RequestBody DictType dictType) {
        return dictTypeService.addDictType(dictType);
    }

    /**
     * 修改字典类型
     */
    @PutMapping
    public Result updateDictType(@Valid @RequestBody DictType dictType) {
        return dictTypeService.updateDictType(dictType);
    }

    /**
     * 删除字典类型
     */
    @DeleteMapping("/{id}")
    public Result deleteDictType(@PathVariable Long id) {
        return dictTypeService.deleteDictType(id);
    }

    /**
     * 批量删除字典类型
     */
    @DeleteMapping("/batch")
    public Result deleteDictTypes(@RequestBody List<Long> ids) {
        return dictTypeService.deleteDictTypes(ids);
    }

    /**
     * 检查字典类型编码是否唯一
     */
    @GetMapping("/check")
    public Result checkDictTypeUnique(
            @RequestParam String dictType,
            @RequestParam(required = false) Long id) {
        return dictTypeService.checkDictTypeUnique(dictType, id);
    }
} 